﻿using UnityEngine;
using System.Collections;

public class WorldEventTrigger : MonoBehaviour
{
	// Properties

	[SerializeField]
	string			m_enterEvent;
	[SerializeField]
	string			m_exitEvent;
	[SerializeField]
	bool			m_onlyForPlayer	= true;


	void OnTriggerEnter2D(Collider2D collider)
	{
		if(!string.IsNullOrEmpty(m_enterEvent))
		{
			BaseCharacter character	= collider.gameObject.GetComponent<BaseCharacter>();
			if(character != null && (character.faction == Faction.Allies || !m_onlyForPlayer))
			{
				GameScene.worldRoot.SendWorldEvent(m_enterEvent, character);
			}
		}
	}

	void OnTriggerExit2D(Collider2D collider)
	{
		if(!string.IsNullOrEmpty(m_exitEvent))
		{
			BaseCharacter character	= collider.gameObject.GetComponent<BaseCharacter>();
			if(character != null && (character.faction == Faction.Allies || !m_onlyForPlayer))
			{
				GameScene.worldRoot.SendWorldEvent(m_exitEvent, character);
			}
		}
	}
}
